package com.gp.testonline.service.impl;

import com.gp.testonline.dao.PersonMapper;
import com.gp.testonline.eo.PersonEOPage;
import com.gp.testonline.model.Person;
import com.gp.testonline.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 *实现业务及流程接口当中的内容
 */
@Service
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonMapper personMapper;


    @Override
    public int InsertPerson(Person person) {
        int isInsert=0;
        /*
         * 业务判断
         * 身份证号不能重复
         */
        int pidcardCount=personMapper.getPidcardCount(person.getPidcard());
        if (pidcardCount<1){
            //返回值
            isInsert=personMapper.insertPerson(person);
        }else{
            isInsert=-1;//有相同身份证号
        }
        return isInsert;
    }

    @Override
    public int UpdatePerson(Person person) {
        int isUpdate=0;
        /*
         * 业务判断
         * 身份证号不能重复
         */
        int pidcardCount=personMapper.getPidcardCount(person.getPidcard());
        if (pidcardCount<1){
            //返回值
            isUpdate=personMapper.updatePerson(person);
        }else{
            isUpdate=-1;//有相同身份证号
        }
        return isUpdate;
    }

    @Override
    public int DeletePerson(Integer pid) {
        int isDelete=0;
        /*1 没有相关业务流程的判断*/
        try{
            isDelete=personMapper.deletePerson(pid);
        }catch (Exception e){
            isDelete=-1;
            //打印更新时报错的情况
            System.out.println("删除人员信息时执行sql报错的原因为："+e.getMessage());
        }
        return isDelete;
    }

    @Override
    public List<PersonEOPage> getPersonAll(PersonEOPage personEOPage) {
        List<PersonEOPage> listPersonEo=personMapper.getPersonAll(personEOPage);
        return listPersonEo;
    }

    //登陆查询
    @Override
    public List<PersonEOPage> getLogin(String paccount,String ppassword) {
        List<PersonEOPage> listLoginEo=personMapper.getLogin(paccount, ppassword);
        return listLoginEo;
    }

    @Override
    public int InsertUsers(Person person) {
        int isInsert=0;
        /*
         * 业务判断
         * 账号不能重复
         */
        int paccountCount=personMapper.getPaccountCount(person.getPaccount());
        if (paccountCount<1){
            //返回值
            isInsert=personMapper.insertUsers(person);
        }else{
            isInsert=-1;//有相同账号
        }
        return isInsert;
    }

    @Override
    public String GetPid(String paccount, String ppassword) {
        String listPidEo=personMapper.getPid(paccount, ppassword);
        return listPidEo;
    }
}
